<template>
    <view class="wanl-money">
        <view class="edgeInsetTop"></view>
        <view class="cu-list menu-avatar" v-if="dataList">
            <view class="list" v-for="(item, index) in dataList" :key="item.id" @tap="toMoney(item)">
                <!--                <view class="cu-avatar round bg-blue" v-if="item.type == 'pay'">
                    <text class="wlIcon-baojiadan"></text>
                </view>
                <view class="cu-avatar round bg-red" v-if="item.type == 'groups'">
                    <text class="wlIcon-baojiadan"></text>
                </view>
                <view class="cu-avatar round bg-cyan" v-else-if="item.type == 'recharge'">
                    <text class="wlIcon-zhanghuyue"></text>
                </view>
                <view class="cu-avatar round bg-orange" v-else-if="item.type == 'withdraw'">
                    <text class="wlIcon-jinbitixian"></text>
                </view>
                <view class="cu-avatar round bg-pink" v-else-if="item.type == 'refund'">
                    <text class="wlIcon-jingjiachenggong"></text>
                </view>
                <view class="cu-avatar round bg-red" v-else>
                    <text class="wlIcon-fuwuqi1"></text>
                </view> -->

                <view class="padding-lr u-flex u-row-between item white-bg u-border-bottom">
                    <view class="u-flex-col">
                        <view class="tips">
                            {{ getTipsByStatus(item.status) }}
                        </view>

                        <view class="time">{{ item.createtime_text }}</view>
                    </view>

                    <view class="price" :class="item.status">-{{ item.money }}</view>
                </view>

            </view>
        </view>
        <!-- 空 -->
        <view v-if="dataList.length == 0">
            <wanl-empty src="ticket_default3x" text="没找到任何账单明细" />
        </view>
        <view class="edgeInsetBottom"></view>
        <uni-load-more :status="status" :content-text="contentText" />
    </view>
</template>

<script>
    export default {
        data() {
            return {
                dataList: [],
                payType: {
                    pay: '商品交易',
                    groups: '拼团',
                    recharge: '充值',
                    withdraw: '提现',
                    refund: '退款',
                    sys: '系统',
                },
                reload: false, //判断是否上拉
                total: 0, //数据量
                current_page: 1, //当前页码
                last_page: 1, //总页码
                status: 'more',
                contentText: {
                    contentdown: ' ',
                    contentrefresh: '加载中',
                    contentnomore: ''
                },
                freeze: 0,
            };
        },
        onLoad(options) {
            this.freeze = options.type
            if (options.type == 1) {

                uni.setNavigationBarTitle({
                    title: '邀请提佣',
                    frontColor: '#ffffff',
                    backgroundColor: '#ff0000',
                    animation: {
                        duration: 400,
                        timingFunc: 'easeIn'
                    }
                })
            }
            this.loadData();
        },
        onPullDownRefresh() {
            this.current_page = 1;
            this.reload = true;
            this.loadData();
        },
        onReachBottom() {
            //判断是否最后一页
            if (this.current_page >= this.last_page) {
                this.status = 'noMore';
            } else {
                this.reload = false;
                this.current_page = this.current_page + 1; //页码+1
                this.status = 'loading';
                this.loadData();
            }
        },
        methods: {
            getTipsByStatus(status) {
                let tips = "申请中";
                if (status == "rejected") {
                    tips = "提现失败"
                } else if (status == "created") {
                    tips = "申请中"
                } else if (status == "successed") {
                    tips = "提现成功"
                }

                return tips;
            },
            async loadData() {
                this.$api.post({
                    url: '/store/store/withdrawList',
                    data: {
                        page: this.current_page,
                    },
                    success: res => {
                        uni.stopPullDownRefresh();
                        this.dataList = this.reload ? res.data : this.dataList.concat(res.data); //数据 追加
                        this.total = res.total; //数据量
                        this.current_page = res.current_page; //当前页码
                        this.last_page = res.last_page; //总页码
                        this.status = res.total == 0 ? 'noMore' : 'more';
                    }
                });
            },
            toMoney(item) {
                // this.$wanlshop.to(`/pages/user/money/details?data=${JSON.stringify(item)}`);
            }
        }
    };
</script>

<style lang="scss" scoped>
    .wanl-money .balance {
        margin: 10rpx 25rpx 25rpx 25rpx;
    }

    .wanl-money .balance .details {
        padding: 50rpx 0;
    }

    .wanl-money .balance .operate {
        display: flex;
        align-items: center;
        justify-content: space-around;
        background: rgba(0, 0, 0, 0.1);
        height: 80rpx;
        color: #fff;
    }

    .wanl-money .cu-list.menu-avatar>.cu-item {
        height: 180rpx;
        align-items: flex-start;
        padding: 25rpx 0;
    }

    .wanl-money .cu-list.menu-avatar>.cu-item .cu-avatar {
        width: 75rpx;
        height: 75rpx;
        left: 25rpx;
        margin-top: 6rpx;
    }

    .wanl-money .cu-list.menu-avatar>.cu-item .content {
        left: 120rpx;
        width: calc(100% - 75rpx - 25rpx - 150rpx);
        line-height: 1.5em;
    }

    .wanl-money .cu-list.menu-avatar>.cu-item .action {
        width: 220rpx;
        text-align: right;
        padding-right: 25rpx;
    }

    .cu-list.menu-avatar .cu-item .content {
        position: absolute;
    }

    .list {
        .item {
            height: 138rpx;
            background: #ffffff;

            .tips {
                font-weight: 500;
                font-size: 28rpx;
                color: #333333;
                line-height: 40rpx;
            }

            .time {
                font-weight: 400;
                font-size: 24rpx;
                color: #999999;
                line-height: 34rpx;
            }

            .price {
                font-size: 40rpx;
                color: #FF4900;
                line-height: 58rpx;
            }
        }
    }
</style>